Scatter matrix plotting

In this notebook I reproduce the scatter plot matrix demo included in the pandas documentation:

http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html#scatter-matrix-plot


In [1]:
import pandas as pd
from pandas.tools.plotting import scatter_matrix
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-2a4f46ab402f> in <module>()
      4 import matplotlib as mpl
      5 import matplotlib.pyplot as plt
----> 6 import seaborn as sns

ImportError: No module named seaborn

In [2]:
# nice plot formatting
plt.style.use('ggplot') # requires v1.4 
mpl.rcParams['font.family'] = 'Ubuntu Mono'
# pd.options.display.mpl_style = 'default' # this is buggy...
# check matplotlib version...
print mpl.__version__


1.4.2

In [3]:
# make a random number generator with the same seed as used in the pandas documentation
rng = np.random.RandomState(seed=123456)

In [4]:
# create dataframe with data to plot
df = pd.DataFrame(rng.randn(1000, 4), columns=['a', 'b', 'c', 'd'])

In [5]:
# create figure with plots
pd.tools.plotting.scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')


Out[5]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7ff38a56b810>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff380029710>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff380064150>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff379a43fd0>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7ff3799c6310>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff3799a2390>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff37991c790>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff3799dda50>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7ff379864f90>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff3797ea310>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff3797c2bd0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff37973ce10>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x7ff37968f690>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff37960b710>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff379601550>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7ff379568290>]], dtype=object)

In [7]:
# save figure to file
plt.savefig('scatter plots (pandas example).png')

In [7]:
font_paths = mpl.font_manager.findSystemFonts()
font_objects = mpl.font_manager.createFontList(font_paths)
font_names = [f.name for f in font_objects]
print font_names


['STIXIntegralsUp', 'Droid Sans Ethiopic', 'Latin Modern Roman', 'Latin Modern Mono Caps', 'Inconsolata', 'Gillius ADF Cd', 'KacstScreen', 'MathJax_Math', 'KacstTitle', 'Norasi', 'Gentium Basic', 'Latin Modern Roman', 'Junicode', 'Gentium Book Basic', 'TakaoPGothic', 'Gentium Book Basic', 'DejaVu Serif', 'Linux Libertine O', 'Asana Math', 'MathJax_Main', 'Accanthis ADF Std No2', 'GFS Didot', 'Latin Modern Roman', 'Latin Modern Mono', 'GFS Olga', 'DejaVu Serif', 'Gillius ADF No2 Cd', 'Latin Modern Roman', 'Tlwg Typist', 'NanumGothic', 'Lato', 'GFS Artemisia', 'Gentium Basic', 'Droid Arabic Naskh', 'Gentium', 'Comfortaa', 'Liberation Sans', 'DejaVu Sans Mono', 'STIXIntegralsUp', 'Latin Modern Roman', 'FontAwesome', 'Droid Sans Hebrew', 'Cabin', 'Droid Arabic Naskh', 'Ubuntu Mono', 'Loma', 'Droid Serif', 'Latin Modern Roman', 'Latin Modern Roman Slanted', 'FreeSerif', 'Latin Modern Mono', 'FreeSans', 'KacstNaskh', 'Kinnari', 'Sawasdee', 'MathJax_Fraktur', 'DejaVu Sans Mono', 'FreeSans', 'Liberation Serif', 'Latin Modern Mono', 'Purisa', 'Tlwg Typist', 'Latin Modern Mono Prop', 'KacstPoster', 'Purisa', 'STIXSizeOneSym', 'Accanthis ADF Std No3', 'Ubuntu', 'Droid Sans Mono', 'Latin Modern Sans', 'FreeSerif', 'STIXIntegralsSm', 'Umpush', 'NanumGothic', 'Liberation Mono', 'FreeSerif', 'Ubuntu Condensed', 'cmsy10', 'OpenSymbol', 'Cabin', 'Norasi', 'Droid Sans Fallback', 'Khmer OS System', 'Tlwg Typist', 'Norasi', 'Lobster Two', 'Latin Modern Roman', 'Mukti Narrow', 'Latin Modern Sans', 'DejaVu Sans', 'Ubuntu', 'NanumBarunGothic', 'Latin Modern Roman', 'Latin Modern Math', 'Latin Modern Roman', 'MathJax_WinChrome', 'MathJax_SansSerif', 'STIXIntegralsD', 'Lohit Tamil', 'Lobster Two', 'Kinnari', 'Latin Modern Sans', 'Andale Mono', 'STIXGeneral', 'Junicode', 'cmmi10', 'GFS Didot', 'Gillius ADF No2 Cd', 'TlwgMono', 'Latin Modern Roman Caps', 'Lato', 'Latin Modern Sans', 'Purisa', 'Kinnari', 'STIXSizeOneSym', 'Saab', 'Ubuntu Mono', 'KacstLetter', 'DejaVu Sans', 'GFS Neohellenic', 'Gillius ADF', 'TlwgTypewriter', 'Latin Modern Mono Prop Light', 'msam10', 'Ubuntu', 'Garuda', 'Tlwg Typist', 'Linux Libertine Mono O', 'FreeSans', 'Ubuntu', 'Linux Libertine O', 'MathJax_Script', 'Droid Sans Armenian', 'Linux Libertine O', 'DejaVu Sans Mono', 'DejaVu Sans', 'DejaVu Sans', 'NanumBarunGothic', 'Junicode', 'MathJax_Size4', 'TlwgMono', 'Liberation Mono', 'Liberation Serif', 'Latin Modern Mono Light', 'Liberation Serif', 'STIXGeneral', 'Waree', 'Pothana2000', 'Latin Modern Mono Light', 'DejaVu Serif', 'ori1Uni', 'Linux Biolinum O', 'Mukti Narrow', 'Latin Modern Roman', 'FreeMono', 'Latin Modern Mono Prop', 'Norasi', 'Kinnari', 'Mallige', 'KacstOne', 'Latin Modern Sans', 'Lato', 'Lohit Bengali', 'Gillius ADF', 'Latin Modern Roman Slanted', 'Latin Modern Mono Slanted', 'Latin Modern Sans Quotation', 'Gillius ADF No2 Cd', 'FreeMono', 'Accanthis ADF Std', 'KacstBook', 'Droid Serif', 'wasy10', 'Lato', 'GFS Neohellenic', 'Comfortaa', 'DejaVu Sans', 'STIXNonUnicode', 'Comfortaa', 'DejaVu Sans', 'GentiumAlt', 'Latin Modern Roman', 'Ubuntu', 'FreeSans', 'Latin Modern Sans', 'STIXNonUnicode', 'Latin Modern Sans Demi Cond', 'Padauk Book', 'Cabin', 'FreeSans', 'DejaVu Serif', 'Kinnari', 'Umpush', 'Accanthis ADF Std No2', 'Droid Sans Ethiopic', 'Purisa', 'GFS Didot', 'Gentium Basic', 'DejaVu Sans', 'Linux Biolinum Keyboard O', 'Phetsarath OT', 'FreeMono', 'MathJax_Size1', 'STIXNonUnicode', 'Latin Modern Roman Slanted', 'Gillius ADF', 'Latin Modern Sans', 'STIXVariants', 'Latin Modern Sans Quotation', 'Sawasdee', 'Latin Modern Roman', 'STIXIntegralsD', 'Khmer OS', 'Padauk', 'KacstDecorative', 'MathJax_Math', 'Gillius ADF No2', 'Gillius ADF Cd', 'Waree', 'FreeMono', 'Lato', 'Latin Modern Mono', 'Gillius ADF No2 Cd', 'STIXIntegralsUpSm', 'Latin Modern Roman', 'Linux Libertine Initials O', 'Gillius ADF No2', 'Latin Modern Roman', 'Umpush', 'Gillius ADF No2', 'Accanthis ADF Std No3', 'Lohit Punjabi', 'Accanthis ADF Std', 'Liberation Mono', 'FreeSerif', 'DejaVu Serif', 'GFS Solomos', 'LKLUG', 'Lohit Devanagari', 'Lato', 'FontAwesome', 'Ubuntu', 'DejaVu Sans', 'TlwgMono', 'MathJax_Main', 'Cabin', 'msbm10', 'DejaVu Serif', 'DejaVu Serif', 'DejaVu Serif', 'NanumMyeongjo', 'TlwgMono', 'STIXSizeTwoSym', 'TakaoPGothic', 'Droid Sans', 'GFS Neohellenic', 'STIXSizeFiveSym', 'Kedage', 'Latin Modern Mono', 'MathJax_AMS', 'Norasi', 'Umpush', 'Liberation Sans', 'Lato', 'Norasi', 'Latin Modern Mono Light Cond', 'Latin Modern Roman Demi', 'Lobster Two', 'MathJax_Caligraphic', 'Ubuntu', 'Latin Modern Sans Demi Cond', 'Linux Libertine O', 'DejaVu Sans', 'KacstFarsi', 'Latin Modern Roman Slanted', 'Latin Modern Mono Light Cond', 'Loma', 'TlwgTypewriter', 'Accanthis ADF Std No2', 'MathJax_Fraktur', 'Latin Modern Roman', 'gargi', 'Latin Modern Roman', 'GFS Artemisia', 'STIXSizeThreeSym', 'GFS Didot', 'Latin Modern Sans', 'Lato', 'FreeMono', 'Accanthis ADF Std No3', 'Gillius ADF Cd', 'MathJax_Size2', 'MathJax_Size3', 'Latin Modern Sans Quotation', 'KacstArt', 'Liberation Sans Narrow', 'Latin Modern Roman Dunhill', 'GFS Didot', 'Liberation Sans', 'Ubuntu Mono', 'Latin Modern Sans', 'STIXSizeTwoSym', 'MathJax_Main', 'Rachana', 'Kinnari', 'Lobster Two', 'TlwgTypewriter', 'Gentium Book Basic', 'Liberation Sans Narrow', 'FreeSerif', 'Latin Modern Roman Slanted', 'STIXGeneral', 'Sawasdee', 'Sawasdee', 'STIXIntegralsSm', 'Kedage', 'cmex10', 'Lohit Gujarati', 'Accanthis ADF Std', 'NanumMyeongjo', 'Lato', 'STIXGeneral', 'GFS Complutum', 'Loma', 'KacstPen', 'STIXSizeFourSym', 'Linux Libertine O', 'FreeSerif', 'Cabin', 'Latin Modern Roman Caps', 'Droid Sans Japanese', 'Liberation Sans Narrow', 'cmr10', 'Mallige', 'Accanthis ADF Std No2', 'Latin Modern Roman', 'Gillius ADF Cd', 'STIXIntegralsUpSm', 'MathJax_SansSerif', 'Junicode', 'Liberation Sans Narrow', 'Latin Modern Mono Light', 'FreeMono', 'Droid Serif', 'Meera', 'Umpush', 'Tlwg Typo', 'Gentium', 'FreeSans', 'Gentium Basic', 'Latin Modern Roman Dunhill', 'Liberation Sans', 'Accanthis ADF Std No3', 'Liberation Mono', 'MathJax_Typewriter', 'STIXVariants', 'Latin Modern Sans', 'rsfs10', 'Gentium Book Basic', 'Garuda', 'mry_KacstQurn', 'Lato', 'Latin Modern Sans', 'Tibetan Machine Uni', 'Cabin', 'Latin Modern Sans Quotation', 'Accanthis ADF Std', 'KacstOne', 'Linux Libertine Display O', 'Latin Modern Mono Caps', 'Lobster Two', 'KacstDigital', 'FreeMono', 'eufm10', 'esint10', 'Latin Modern Roman', 'STIXIntegralsUpD', 'MathJax_SansSerif', 'Latin Modern Roman Demi', 'Gillius ADF', 'Cabin', 'Droid Sans Georgian', 'GFS Artemisia', 'Ubuntu Mono', 'Latin Modern Mono Light', 'Linux Libertine O', 'Linux Biolinum O', 'Latin Modern Mono Prop Light', 'Latin Modern Roman', 'Padauk', 'DejaVu Sans Mono', 'Rekha', 'Garuda', 'MathJax_WinIE6', 'MathJax_Caligraphic', 'Latin Modern Mono Prop Light', 'Latin Modern Roman Slanted', 'GentiumAlt', 'Umpush', 'Droid Serif', 'Tlwg Typo', 'Cabin', 'Liberation Serif', 'TlwgTypewriter', 'Waree', 'STIXNonUnicode', 'FreeSerif', 'Vemana2000', 'STIXSizeThreeSym', 'Tlwg Typo', 'Droid Sans', 'Waree', 'Latin Modern Mono Prop Light', 'GFS Neohellenic', 'FreeSans', 'Ubuntu', 'Droid Sans Thai', 'Latin Modern Roman Unslanted', 'Latin Modern Sans', 'Gillius ADF No2', 'STIXSizeFourSym', 'Linux Biolinum O', 'KacstQurn', 'FreeSans', 'Padauk Book', 'Latin Modern Roman', 'KacstOffice', 'Abyssinica SIL', 'FreeSerif', 'STIXIntegralsUpD', 'Loma', 'Garuda', 'Latin Modern Roman', 'Tlwg Typo', 'FreeMono', 'KacstTitleL', 'MathJax_Math', 'Droid Sans Hebrew']

In [ ]: